package com.config;/*
 *
 *作者：张继成
 *任务：
 *
 *备注：
 *@Date2023/06/23/16:50
 ***/

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
@Data
@Component
//读取application当中的一个配置，所有alipay开头的配置填充至属性
@ConfigurationProperties(prefix = "alipay")
public class AliPayConfig {
    private String appId;
    private String appPrivateKey;
    private String alipayPublicKey;
    private String notifyUrl;


    @PostConstruct
    public void init() {
        // 设置参数（全局只需设置一次）
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi-sandbox.dl.alipaydev.com";
        config.signType = "RSA2";

        config.appId = this.appId;
        System.out.println(config.appId);
        System.out.println("------------------------------------------------");
        config.merchantPrivateKey = this.appPrivateKey;
        System.out.println(config.merchantPrivateKey);
        System.out.println("------------------------------------------------");
        config.alipayPublicKey = this.alipayPublicKey;
        System.out.println(config.alipayPublicKey);

        config.notifyUrl = this.notifyUrl;
        Factory.setOptions(config);
//        System.out.println(JSONUtil.toJsonStr(config));
        System.out.println("=======支付宝SDK初始化成功=======");
    }
}
